package com.yisingle.study.map.one.fragment.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;

import com.amap.api.maps.AMap;
import com.amap.api.maps.TextureMapView;

/**
 * @author jikun
 *         Created by jikun on 2018/3/13.
 */

public class BaseMapFragment extends Fragment {

    private TextureMapView textureMapView;

    public void initMapView(TextureMapView mapView, @Nullable Bundle savedInstanceState) {
        this.textureMapView = mapView;
        if (null != textureMapView) {
            textureMapView.onCreate(savedInstanceState);
        }
    }


    /**
     * 方法必须重写 来实现TextureMapView的生命周期方法
     */
    @Override

    public void onResume() {
        super.onResume();
        if (null != textureMapView) {
            textureMapView.onResume();
        }

    }

    /**
     * 方法必须重写 来实现TextureMapView的生命周期方法
     */
    @Override
    public void onPause() {
        super.onPause();
        if (null != textureMapView) {
            textureMapView.onPause();
        }
    }

    /**
     * 方法必须重写 来实现TextureMapView的生命周期方法
     */
    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        if (null != textureMapView) {
            textureMapView.onSaveInstanceState(outState);
        }
    }

    /**
     * 方法必须重写 来实现TextureMapView的生命周期方法
     */
    @Override
    public void onDestroy() {
        super.onDestroy();
        if (null != textureMapView) {
            textureMapView.onDestroy();
        }
    }

    public TextureMapView getTextureMapView() {
        return textureMapView;
    }

    public void setTextureMapView(TextureMapView textureMapView) {
        this.textureMapView = textureMapView;
    }

    public AMap getAMap() {
        return getTextureMapView().getMap();
    }
}
